﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Avatar.Model;
using AvatarHelper;
using System.Web.Security;
using Avatar.Company;

public partial class PartTimeJobs : System.Web.UI.Page
{
    int _pageJob;
    int _pageResume;
    int _take = 15;
    public int _serviceID=1;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Page.Title += "兼职专区";
            this.JobBind(_pageJob);
            this.ResumeBind(_pageJob);

            var _user = Membership.GetUser();
            if (_user != null)
            {
                var _service = CompanyServiceManager.GetServiceType(_user.UserName);
                if (_service != null)
                {
                    _serviceID = _service.ServiceTypeID;
                }
            }
        }
    }
    protected void JobBind(int _pageJob)
    {
        using (var _adc = DBHelper.GetDataContext())
        {
            lbl_CurrentJob.Text = (_pageJob + 1).ToString();
            lbl_TotalJob.Text = (_adc.Job.Count(j => j.JobTypeID == 2) / _take + 1).ToString();
            ListView1.DataSource = _adc.Job.Where(j => j.JobTypeID == 2).OrderByDescending(j => j.PublishDate).Skip(_take * _pageJob).Take(_take);
            ListView1.DataBind();
        }
    }
    protected void ResumeBind(int _pageResume)
    {
        using (var _adc = DBHelper.GetDataContext())
        {
            lbl_CurrentR.Text = (_pageResume + 1).ToString();
            lbl_TotalR.Text = (_adc.Resume.Count(r => r.JobIntention != null && r.JobIntention.JobTypeID == 2) / _take + 1).ToString();
            ListView2.DataSource = _adc.Resume.Where(r => r.JobIntention != null && r.JobIntention.JobTypeID == 2).OrderByDescending(r => r.UpdateDate).Skip(_take * _pageResume).Take(_take);
            ListView2.DataBind();
        }
    }
    protected void btn_UpJob_Click(object sender, EventArgs e)
    {
        _pageJob = Convert.ToInt32(lbl_CurrentJob.Text) - 1;
         if (_pageJob > 0) _pageJob -= 1;
         this.JobBind(_pageJob);
    }
    protected void btn_DownJob_Click(object sender, EventArgs e)
    {
        _pageJob = Convert.ToInt32(lbl_CurrentJob.Text) - 1;
        if (_pageJob < Convert.ToInt32(lbl_TotalJob.Text) - 1) _pageJob += 1;
        this.JobBind(_pageJob);
    }
    protected void btn_Goto_Click(object sender, EventArgs e)
    {
        try
        {
            if (!string.IsNullOrEmpty(txt_PageJob.Text)) _pageJob = Convert.ToInt32(txt_PageJob.Text) - 1;
        }
        catch { }
        this.JobBind(_pageJob);
    }
    protected void btn_UpR_Click(object sender, EventArgs e)
    {
        _pageResume = Convert.ToInt32(lbl_CurrentR.Text) - 1;
        if (_pageResume > 0) _pageResume -= 1;
        this.ResumeBind(_pageResume);
    }
    protected void btn_DownR_Click(object sender, EventArgs e)
    {
        _pageResume = Convert.ToInt32(lbl_CurrentR.Text) - 1;
        if (_pageResume < Convert.ToInt32(lbl_TotalR.Text) - 1) _pageResume += 1;
        this.ResumeBind(_pageResume);
    }
    protected void btn_GotoR_Click(object sender, EventArgs e)
    {
        try
        {
            if (!string.IsNullOrEmpty(txt_PageR.Text)) _pageResume = Convert.ToInt32(txt_PageR.Text) - 1;
        }
        catch { }
        this.ResumeBind(_pageResume);
    }
}
